﻿namespace PugLib.UnitTest
{
    using System;
    using System.Threading;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Threading;

    [TestClass]
    public class ForkTest
    {
        [TestMethod]
        public void ForkQueueTest()
        {
            //declare the variables we want to assign
            int str = -1, val = -1;

            //start a new async fork
            //assign the variables inside the fork 

            Fork.Begin()
                .Enqueue(() => str = Sleep(123))
                .Enqueue(() => val = Sleep(321))
                .Enqueue(() => str = Sleep(666))
                .Enqueue(() => val = Sleep(333))
                .End();

            //the fork has finished 

            //we can use the variables now
            Console.WriteLine("{0} {1}", str, val);
        }

        private static int Sleep(int millisecondsTimeout)
        {
            Thread.Sleep(millisecondsTimeout);
            return millisecondsTimeout;
        }
    }
}